#include "gdt.h"

gdt_entry	gdt_entries[5];
gdt_pointer	gdt_ptr;

extern gdt_flush(unsigned int);
	/*
	 * TODO: move gdt_flush.s to this file.
	 */

static void gdt_set_gate(unsigned int num, unsigned int base, unsigned int limit, unsigned char access, unsigned char gran)
{
	/*
	 * TODO: make this function.
	 */
}

static void init_gdt()
{
	gdt_ptr.limit = (sizeof(gdt_entry) * 5) - 1;	// the limit is the size of the table - 1, because this is the last accessable address
	gdt_ptr.base  = (unsigned int)&gdt_entries;		// the starting address of the table

	/*
	 * these are required to be the first in the GDT
	 */
	gdt_set_gate(0, 0, 0, 0, 0);				// null segment (maybe used for pointer to itselfs later)
	gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);	// Code segment
	gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);	// Data segment
	gdt_set_gate(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);	// User mode code segment
	gdt_set_gate(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);	// User mode data segment

	gdt_flush((unsigned int)&gdt_ptr);	// This will make the processor to use our GDT.
}
